package com.guigu.service.impl.stock;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.mapper.stock.SFirstProductAreaMapper;
import com.guigu.pojo.stock.SFirstProductArea;
import com.guigu.pojo.stock.SThirdProductArea;
import com.guigu.pojo.stock.SWarehouseSetting;
import com.guigu.service.stock.SFirstProductAreaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-25
 */
@Service
public class SFirstProductAreaServiceImpl extends ServiceImpl<SFirstProductAreaMapper, SFirstProductArea> implements SFirstProductAreaService {

    @Autowired
    SFirstProductAreaMapper sFirstProductAreaMapper;

    //添加一级分类库存存储区域
    @Override
    public Boolean insertSfirstProArea(SFirstProductArea sFirstProductArea) {
        int r = sFirstProductAreaMapper.insert(sFirstProductArea);
        return r > 0;
    }

    @Override
    public PageInfo<SFirstProductArea> selectAllFirst(HashMap<String, Object> map) {
        Integer pageNum = 1;
        Integer pageSize = 5;
        Object pageNumObj = map.get("pageNum");
        if (pageNumObj != null && StringUtils.isNotBlank((String) pageNumObj)) {
            pageNum = Integer.parseInt((String) pageNumObj);
        }
        Object pageSizeObj = map.get("pageSize");
        if (pageSizeObj != null && StringUtils.isNotBlank((String) pageSizeObj)) {
            pageSize = Integer.parseInt((String) pageSizeObj);
        }
        PageHelper.startPage(pageNum,pageSize);
        ArrayList<SFirstProductArea> sFirstProductAreas = sFirstProductAreaMapper.selectAllFirstPro();

        PageInfo<SFirstProductArea> pageInfo = new PageInfo<>(sFirstProductAreas);
        return pageInfo;
    }

    @Override
    public SFirstProductArea selectOne(String firstId) {
        QueryWrapper<SFirstProductArea> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("FIRST_ID",firstId);
        SFirstProductArea sFirstProductArea = sFirstProductAreaMapper.selectOne(queryWrapper);
        return sFirstProductArea;
    }
}
